"""
* 这是一道模拟题
* 对于Pyhton来说可以霸王硬上弓
https://www.acwing.com/problem/content/1247/
"""
def resolution1():
    special_number_sum = 0
    n = int(input())
    for i in range(1, n+1):
        if '2' in str(i):
            special_number_sum += int(i)
        elif '0' in str(i):
            special_number_sum += int(i)
        elif '1' in str(i):
            special_number_sum += int(i)
        elif '9' in str(i):
            special_number_sum += int(i)
    print(special_number_sum)


if __name__ == '__main__':
    resolution1()